import { fetchGoodsList } from '../../../services/good/fetchGoodsList';

const initFilters = {
  overall: 1,
  sorts: '',
  layout: 0,
};

Page({
  data: {
    goodsList: [],
    layout: 0,
    sorts: '',
    overall: 1,
    show: false,
    minVal: '',
    maxVal: '',
    filter: initFilters,
    hasLoaded: false,
    loadMoreStatus: 0,
    loading: true,
  },

  pageNum: 1,
  pageSize: 100,
  total: 0,

  async init(groupId, reset = true) {
    const { loadMoreStatus, goodsList = [] } = this.data;
    const params = {};
    params.groupId = groupId
    if (loadMoreStatus !== 0) return;
    this.setData({
      loadMoreStatus: 1,
      loading: true,
    });
    const result = await fetchGoodsList(params);
    // console.log("result", result);
    this.setData({
      goodsList: result
    });

  },

  onShareAppMessage: function () {
    return {
      title: '枫味日记',
      path: '/pages/home/home',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },
  onShareTimeline: function () {
    return {
      title: '枫味日记',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },

  onLoad(options) {
    this.init(options.groupId, true);
  },

  gotoGoodsDetail(e) {

    const { index } = e.detail;
    const { saasId } = this.data.goodsList[index];

    // console.log("saasId", saasId)


    wx.navigateTo({
      url: `/pages/goods/details/index?saasId=${saasId}`,
    });
  },
});
